<?php

namespace app\admin\controller;

use app\common\api\controller\Relation;
use app\common\model\Member;
use app\common\model\MemberFinance;
use think\Db;


class Test extends Home
{

    public function index()
    {
        $this->assign('title', "数据初始化");
        return $this->fetch();
    }

    /**
     * 清空所有数据
     */
    public function deleteData()
    {
        $prefix = config('database.prefix');//表前缀
        $sql = " truncate {$prefix}money_change";
        Db::execute($sql);

        $sql = " truncate {$prefix}bonus_count";
        Db::execute($sql);

        $sql = " truncate {$prefix}bonus_total";
        Db::execute($sql);

        $sql = " truncate {$prefix}liuyan";
        Db::execute($sql);

        $sql = " truncate {$prefix}member";
        Db::execute($sql);

        $sql = " truncate {$prefix}ucenter_member";
        Db::execute($sql);

        $sql = " truncate {$prefix}ad";
        Db::execute($sql);

        $sql = " truncate {$prefix}shoplist";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_order";
        Db::execute($sql);

        $sql = " truncate {$prefix}shopcart";
        Db::execute($sql);

        $sql = " truncate {$prefix}transport";
        Db::execute($sql);

        $sql = " truncate {$prefix}withdrawal";
        Db::execute($sql);

        $sql = " truncate {$prefix}recharge";
        Db::execute($sql);

        $sql = " truncate {$prefix}finance";
        Db::execute($sql);

        $sql = " truncate {$prefix}prize";
        Db::execute($sql);

//        clean_all_cache();
        $this->success('数据表清空成功！', url('User/registuser'));
    }

    /**
     * 删除奖金
     */
    function deleteBonus()
    {
        $prefix = config('database.prefix');//表前缀
        $sql = " truncate {$prefix}money_change";
        Db::execute($sql);

        $sql = " truncate {$prefix}bonus_count ";
        Db::execute($sql);

        $sql = " truncate {$prefix}bonus_total";
        Db::execute($sql);

        $sql = " truncate {$prefix}finance";
        Db::execute($sql);

//        $sql = " truncate {$prefix}layer";
//        Db::execute($sql);
//        clean_all_cache();
        $this->success('奖金表清空成功！');
    }

    public function deleteShop()
    {
        $prefix = config('DB_PREFIX');//表前缀
        $sql = " truncate {$prefix}shop";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_category";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_buy";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_see";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_log";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_order";
        Db::execute($sql);

        $sql = " truncate {$prefix}shoplist";
        Db::execute($sql);

        $sql = " truncate {$prefix}shopcart";
        Db::execute($sql);

        $sql = " truncate {$prefix}shop_transport";
        Db::execute($sql);

        $this->success('数据表清空成功！');
    }

    public function tzone()
    {
        echo '非法操作！';
        die;
//        Db('member')->where('tuijianid', 8)->where('tzone', '>', 0)->setInc('tzone', 1);

//        $bonus = new \app\common\api\controller\Bonus();
//        $bonus->unFreezeFund(8);
    }

    public function changeRecomNum()
    {
        echo '非法操作！';
        die;
        $members = Db('member')->field('uid,recom_num')->select();
        $str = '';
        foreach ($members as $v) {
            $sonsNum = Db('member')->where('tuijianid', $v['uid'])->where('status', 1)->count();
            if ($v['recom_num'] != $sonsNum) {
                $str .= '---' . $v['uid'] . '(' . $v['recom_num'] . ',' . $sonsNum . ')';
//                Db('member')->where('uid', $v['uid'])->setField('recom_num', $sonsNum);
            }
        }

        var_dump($str);
        die;
    }

//    public function test(){
//        $uinfo = Member::all([1,6,8]);
//        foreach($uinfo as $user){
//            // 获取用户关联的profile模型数据
//            $finance = $uinfo->finance;
//            var_dump(MemberFinance::getLastSql());
//        }
////        $finance = $uinfo->finance;
////        var_dump(Member::getLastSql());die;
//    }
}
